package cn.stylefeng.guns.modular.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.entity.IdjFeedback;
import cn.stylefeng.guns.modular.mapper.IdjFeedbackMapper;
import cn.stylefeng.guns.modular.service.IIdjFeedbackService;
import cn.stylefeng.roses.core.util.ToolUtil;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 反馈列表 服务实现类
 * </p>
 *
 * @author TANGWJ
 * @since 2020-08-25
 */
@Service
public class IdjFeedbackServiceImpl extends ServiceImpl<IdjFeedbackMapper, IdjFeedback> implements IIdjFeedbackService {

	@Autowired
	private IdjFeedbackMapper mapper;
	
	@Override
	public LayuiPageInfo getList(Page<IdjFeedback> page, String keyword, String beginTime, String endTime) {
		Page<Map<String,Object>> list = mapper.getList(page, keyword, beginTime, endTime);
		return LayuiPageFactory.createPageInfo(list);
	}

	@Override
	public ModelAndView edit(Long id) {
		IdjFeedback feedback = mapper.selectByKeyId(id);
		if(feedback != null){
			if(feedback.getStatus() == 1){
				feedback.setStatusName("待处理");
			}else{
				feedback.setStatusName("已处理");
			}
			if(ToolUtil.isNotEmpty(feedback.getFeedbackPicture())){
				List<String> imgList = new ArrayList<String>();
				String[] split = feedback.getFeedbackPicture().split(",");
				for (int i = 0; i < split.length; i++) {
					imgList.add(split[i]);
				}
				feedback.setImgList(imgList);
			}
		}
		ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("feedback", feedback);
        return modelAndView;
	}

}
